﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dark_Core_Library.UniModules.Models
{

    /// <summary>
    /// 操作结果
    /// </summary>
    /// <typeparam name="TSender">源类型</typeparam>
    /// <typeparam name="TResult">结果类型</typeparam>
    public class UniOperationResult<TSender,TResult>
    {
        /// <summary>
        /// 该值指示是否成功操作
        /// </summary>
        public bool IsSuccess { set; get; }
        /// <summary>
        /// 该值指示操作的消息
        /// </summary>
        public string Message { set; get; }
        /// <summary>
        /// 操作源对象数据
        /// </summary>
        public TSender Sender { set; get; }
        /// <summary>
        /// 操作结果数据
        /// </summary>
        public TResult Result { set; get; }

        private UniOperationResult(bool isSuccess, string message,TSender sender,  TResult result)
        {
            this.IsSuccess = isSuccess;
            this.Message = message;
            this.Sender = sender;
            this.Result = result;
        }

        /// <summary>
        /// 创建操作结果对象
        /// </summary>
        /// <typeparam name="S">源类型</typeparam>
        /// <typeparam name="R">结果类型</typeparam>
        /// <param name="sender">源对象</param>
        /// <param name="result">结果对象</param>
        /// <param name="message">操作消息</param>
        /// <param name="isSuccess">操作是否成功</param>
        /// <returns></returns>
        public static UniOperationResult<S,R> CreateInstance<S,R>(S sender,R result,string message,bool isSuccess = true)
        {
            return new UniOperationResult<S, R>(isSuccess, message, sender, result);
        }

    }
}
